﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
    string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["xxnewsConnectionString"].ConnectionString;
    SqlConnection sqlcon;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string sqlstr = "";
            switch (Request.QueryString["lb"])
            {
                case "主卡充值":
                    sqlstr = "select ch_pwname,in_id FROM siteman WHERE (ch_pwname = '材料科') ORDER BY ch_px";
                    break;
                case "基础数据":
                    sqlstr = "select ch_pwname,in_id FROM siteman WHERE (ch_pwname = '设备科') ORDER BY ch_px";
                    break;
				case "主卡明细":
					sqlstr = "select ch_pwname,in_id FROM siteman WHERE (ch_pwname = '材料科' or ch_pwname = '设备科') ORDER BY ch_px";
					break;
				default:
                    sqlstr = "select ch_pwname,in_id FROM siteman WHERE (ch_pwname = '设备科') or (ch_pwname = '材料科') or ch_pwname in(SELECT DISTINCT banzu1 FROM tcjcb) or ch_pwname in(SELECT DISTINCT banzu1 FROM tcjcb_qiche)  or ch_pwname in(SELECT DISTINCT banzu1 FROM tcjcb_fadianji) group by ch_pwname,in_id,ch_px ORDER BY ch_px";
                    break;
            }
            Session["lb"] = Request.QueryString["lb"];
            try
            {
                sqlcon = new SqlConnection(strCon);
                SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
                DataSet myds = new DataSet();
                myda.Fill(myds, "siteman");
                id.DataSource = myds;
                id.DataBind();
            }catch (SqlException){throw;}
        }
        mima.Focus();
        mima.Attributes.Add("onmouseover", "this.focus()");
        mima.Attributes.Add("onfocus", "this.select()");
        id.Attributes.Add("onchange", "mima.focus()");
        if (mima.Text != "")
        {
            try
            {
                string sqlstr1 = "select * from siteman where in_id='" + id.SelectedItem.Value + "' and ch_pwd='" + mima.Text + "'";
                //Response.Write(sqlstr);
                sqlcon = new SqlConnection(strCon);
                SqlDataAdapter myda1 = new SqlDataAdapter(sqlstr1, sqlcon);
                DataSet myds1 = new DataSet();
                //sqlcon.Open();
                myda1.Fill(myds1, "siteman1");
                if (myds1.Tables[0].Rows.Count == 0)
                {
                    Response.Write("<SCRIPT language=javascript>alert('密码错误！');</SCRIPT>");
                }
                else
                {
                    Session["pn"] = myds1.Tables[0].Rows[0]["ch_pwname"].ToString();
                    if (myds1.Tables[0].Rows[0]["ch_pwname"].ToString() == "小车班")
                    {
                        Session["pnchejian"] = "办公室";
                    }
                    else if (myds1.Tables[0].Rows[0]["ch_pwname"].ToString() == "材料科")
                    {
                        Session["pnchejian"] = "材料科";
                    }
                    else if (myds1.Tables[0].Rows[0]["ch_pwname"].ToString() == "设备科")
                    {
                        Session["pnchejian"] = "设备科";
                    }
                    else
                    {
                        Session["pnchejian"] = myds1.Tables[0].Rows[0]["bm_leibie"].ToString();
                    }
                    Response.Redirect("default2.aspx?"
						+ (!string.IsNullOrEmpty(Request["lb"]) ? ("&lb=" + Request["lb"]) : string.Empty)
						+ (!string.IsNullOrEmpty(Request["type"]) ? ("&type=" + Request["type"]) : string.Empty)
						);
                }
            }catch (SqlException) { throw; }
        }
    }
}
